package com.leo.dao;

import com.leo.persistence.io.Resources;
import com.leo.persistence.sqlSession.SqlSession;
import com.leo.persistence.sqlSession.SqlSessionFactory;
import com.leo.persistence.sqlSession.SqlSessionFactoryBuilder;
import com.leo.pojo.User;

import java.io.InputStream;
import java.util.List;

public class UserDaoImpl implements IUserDao {

    @Override
    public List<User> selectList() throws Exception {
        // 1.加载配置文件
        InputStream in = Resources.getResourceAsStream("sqlMapConfig.xml");
        // 2.解析到两个配置到bean，并创建sqlSessionFactory
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
        // 3.获取session
        SqlSession session = sqlSessionFactory.openSession();



        List<User> list = session.selectList("com.leo.dao.IUserDao.selectList");
        return list;
    }

    @Override
    public User selectOne(User user) throws Exception {
        // 1.加载配置文件
        InputStream in = Resources.getResourceAsStream("sqlMapConfig.xml");
        // 2.解析到两个配置到bean，并创建sqlSessionFactory
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
        // 3.获取session
        SqlSession session = sqlSessionFactory.openSession();



        User res = session.selectOne("com.leo.dao.IUserDao.selectOne", user);
        return res;
    }

    @Override
    public User selectByMultiParam(int id, String username) throws Exception {
        return null;
    }

    @Override
    public int insert(User user) {
        return 0;
    }

    @Override
    public int update(User user) {
        return 0;
    }

    @Override
    public int delete(int id) {
        return 0;
    }
}
